/**
 * \file SourceFile.cpp
 *
 * ICC Driver
 * Written 2011, by Anthony Berlin and Alexander Carlqvist
 *
 * This file is part of ICC.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "SourceFile.h"

///
/// \brief Constructors for \c SourceFile.
/// \param path The path to the source file.
///
SourceFile::SourceFile(const char* path)
{
    m_location = "";
    m_filename = "";
    m_extension = "";

    vector<string> splitVector;

    string pathstr = "";

    // Get the file extension from the path, if there is one.
    if (path[strlen(path) - 4] == '.')
    {
        vector<string> splitVector3;
        split(splitVector3, path, boost::is_any_of("."), boost::token_compress_on);
        set_extension(splitVector3[splitVector3.size()-1]);
        pathstr = splitVector3[splitVector3.size()-2].c_str();
    }

    // Get the file path and file name from the 'path' variable.
    string name = "";
    string loc = "";
    char character = 0;

    for (unsigned int i = 0; i < pathstr.size(); ++i)
    {
        character = pathstr[i];
        name += character;
        if (character == '\\' || pathstr[i] == '/')
        {
            loc += name;
            name = "";
        }
    }

    // Remove unnecessary '/' or '\' characters.
    if (loc != "" && (loc[loc.size()-1] == '/' || loc[loc.size()-1] == '\\'))
        loc = loc.substr(0, loc.size()-1);

    set_name(name);
    set_location(loc);
}

SourceFile::SourceFile()
{
    m_location = "";
    m_filename = "";
    m_extension = "";
}

///
/// \brief Get the full path (\c m_location, \c m_filename and \c m_extention combined).
/// \return A \c string containing the full path.
///
string SourceFile::get_full_path()
{
    return m_location + "/" + m_filename + "." + m_extension;
}

///
/// \brief Get the full file name (\c m_filename and \c m_extention combined).
/// \return A \c string containing the full file name.
///
string SourceFile::get_full_name()
{
    return m_filename + "." + m_extension;
}

///
/// \brief Get the location (path) of the source file.
/// \return A \c string containing the path of the source file.
///
string SourceFile::get_location()
{
    return m_location;
}

///
/// \brief Get the name (without the extension) of the source file.
/// \return A \c string containing the name of the source file.
///
string SourceFile::get_name()
{
    return m_filename;
}

///
/// \brief Get the file extension of the source file.
/// \return A \c string containing the file extension of the source file.
///
string SourceFile::get_extension()
{
    return m_extension;
}

///
/// \brief Set the location (path) of the source file.
/// \param location The \c string containing the path of the source file.
///
void SourceFile::set_location(string location)
{
    m_location = location;
}

///
/// \brief Set the name (without the extension) of the source file.
/// \return The \c string containing the name of the source file.
///
void SourceFile::set_name(string name)
{
    m_filename = name;
}

///
/// \brief Set the file extension of the source file.
/// \return The \c string containing the file extension of the source file.
///
void SourceFile::set_extension(string extension)
{
    m_extension = extension;
}
